import { http } from '@/utils/http';
import type { OpenIdItem, SlientInfoItem, Phone, Teacher } from './index.d';

export { OpenIdItem, Phone, Teacher };

/** 获取用户openid */
export const getUserOpenid = (code: string) => {
	return http<OpenIdItem>({
		url: `/api/auth/wx_verify`,
		method: 'POST',
		data: { code },
	});
};

/** 获取用户静默登录信息 */
export const getSlientInfoApi = (code: string) => {
	return http<any>({
		url: `/api/auth/login_silent_wx`,
		method: 'POST',
		data: { code },
	});
};

/** 获取教师信息 */
export const getTeacherAllInfoApi = () => {
	return http<any>({
		url: `/api/teacher/get_teacher_all_info`,
		method: 'POST',
	});
};

/** 获取用户手机号 */
export const getUserPhone = (data: Phone.Params) => {
	return http<Phone.Data>({
		url: `/api/auth/login_wx`,
		method: 'POST',
		data,
	});
};

/** 获取用户默认登录的学生账号 */
export const getDefaultUserInfo = () => {
	return http<Teacher.DefaultUserInfo>({
		url: `/api/teacher/get_teacher_all_info`,
		method: 'POST',
	});
};

/** 设置用户默认登录的学生账号 */
export const setDefaultUserInfo = (id: number) => {
	return http<Teacher.DefaultUserInfo>({
		url: `/api/student/student_set_default`,
		method: 'POST',
		data: id ? { student_id: id } : {},
	});
};

/** 获取所有学生列表 */
export const getStudentList = () => {
	return http<Teacher.StudentList[]>({
		url: `/api/student/student_list`,
		method: 'POST',
	});
};

/** 用户添加教师账号 */
export const addTeacherInfo = (data: Teacher.AddParams) => {
	return http({
		url: `/api/teacher/add_teacher_grade`,
		method: 'POST',
		data,
	});
};

/** 用户编辑老师账号 */
export const editTeacherInfo = (data: Teacher.AddParams) => {
	return http({
		url: `/api/teacher/edit_teacher_grade`,
		method: 'POST',
		data,
	});
};

/** 用户编辑学生账号 */
export const editStudentAvatar = (data: Teacher.EditAvatarParams) => {
	return http<Teacher.EditAvatarData>({
		url: `/api/student/upload_student_avatar`,
		method: 'POST',
		data,
	});
};

/** 获取学生信息及阅读统计数据 */
export const getMyCenterInfo = () => {
	return http<Teacher.CenterInfoData>({
		url: `/api/teacher/teacher_statistics`,
		method: 'POST',
	});
};
/** 退出登录 */
export const userLogout = () => {
	return http({
		url: `/api/auth/logout`,
		method: 'GET',
	});
};
